package main;

import Operation.ExitOperation;
import Operation.IOperation;
import USer.Adminuser;
import USer.Normaluser;
import USer.User;
import book.BookList;

import java.util.Scanner;


//实现自定义异常
//自己弄一个默认用户名和密码，如果不同则输出错误
public class Main {

    public static User longin() throws UserNameException{
        Scanner scanner=new Scanner(System.in);
        System.out.print("请输入你的姓名：");
        String name=scanner.next();
      try {
         User user=new Adminuser();
         user.func(name);
      }catch (UserNameException e) {
       e.printStackTrace();
          System.out.println("用户名错误");
          System.exit(0);
      }
        System.out.println("请选择你的身份：");
        System.out.println("1.管理员  2. 普通用户 ");
        int n=scanner.nextInt();
        while(true) {
            if(n==1) {
                //管理员
                return new Adminuser(name);
            } else if (n==2){
                //普通用户
                return new Normaluser(name);
            }
        }
    }
    public static void main(String[] args) throws UserNameException{
        BookList booklist=new BookList();
        Scanner scanner=new Scanner(System.in);
        User user=longin();
       int n=0;
        user.mnum();
       while(true){
           System.out.println("请输入你的选择 ");
           n=scanner.nextInt();
           if(n>6||n<0) {
               return;
           }
        user.doWork(n,booklist);
       }
    }
}
